/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.additional;

import com.sun.lwuit.Component;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.list.DefaultListCellRenderer;
import datamodel.Message;

/**
 *
 * @author Kvest
 */
public class MessageListRenderer extends DefaultListCellRenderer
{
    private Image readIcon, unreadIcon;
    
    public MessageListRenderer(Image readIcon, Image unreadIcon)
    {
        super(false);
        
        this.readIcon = readIcon;
        this.unreadIcon = unreadIcon;
    }
    
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
    {
        Label element = (Label)super.getListCellRendererComponent(list,value,index,isSelected);
        element.setEndsWith3Points(true);
        
        if (value != null && (value instanceof Message))
        {
            if (((Message)value).isRead())
            {
                element.setIcon(readIcon);
            }
            else
            {
                element.setIcon(unreadIcon);
            }
        }
        
        return element;
    }
}
